Skip to content

perf(server): a folder's repo root is remembered, not asked of git on every lookup - #1037

Merged
badcuban merged 1 commit into
mainfrom
perf/repository-identity-lookups
Nov 21, 2026
Merged

badcuban merged 1 commit into
mainfrom
perf/repository-identity-lookups

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Problem

RepositoryIdentityResolver ran git rev-parse --show-toplevel on every resolve(cwd), because git's answer was the key of the identity cache. So the cache never saved that process. On a real install the pull request sweep made 32 of these per pass over 11 project folders, every 20 to 120 seconds. Together with the other callers it was about 18 of the 52 child processes the server started each minute.

Fix

The resolver remembers each folder's repository root and confirms it with file checks instead of starting git:

  • the folder still resolves to the same real path,
  • no folder between it and the root holds a .git or a HEAD (a bare repository),
  • the root's .git still exists.

When a check fails, the next resolve asks git again at once. Remembered roots are also re-asked every 10 minutes. An answer the disk can't confirm (git timed out, a symlink git resolved differently, a .git git skipped) is never reused, so those folders behave as before. Concurrent resolves of one folder share one git run. The fix is in the resolver, so every caller gets it.

Git root lookups, 11 folders Before After
First sweep 32 11
Each later sweep 32 0

How fast a change is noticed

Change Before After
git init in a folder with no repo next resolve next resolve
Repo nested under a remembered root, bare or not next resolve next resolve
Folder replaced by a different repo up to 1 min up to 1 min
Remote URL changed up to 1 min up to 1 min
A change the file checks can't see, such as core.worktree being set next resolve up to 10 min

The last row is the trade this change makes.

Tests. New tests count git runs through the process runner: repeated and concurrent resolves, the 10-minute re-ask, a nested repo, a nested bare repo (fails without the HEAD check), git init, and a folder re-created as another repo. The resolver's 12 tests pass, along with the 462 tests in the files that build the real resolver, and fmt, lint and typecheck.

Review. An independent review of the diff found three things. Fixed: a bare repository created inside another repo kept the parent's identity for 10 minutes. Fixed in code, not run on Windows: git prints //server/share/repo for a network share while the filesystem says \\server\share\repo, so the two never matched and the lookup was never remembered; the separators are converted before comparing. Left as is: the bounded cache can evict an entry whose lookup is still running, so two lookups for one folder can overlap if 512 other folders are resolved in the meantime. Before this change no lookups were shared at all.

Not checked. A run on Windows, and a live server.

… every lookup

RepositoryIdentityResolver ran `git rev-parse --show-toplevel` on every
resolve, because git's answer was the identity cache's key. The pull
request sweep alone made 32 of those per pass over 11 folders, every 20
to 120 seconds, about a third of the child processes the server starts.

The resolver now remembers each folder's root and confirms it on disk:
the folder still resolves to the same real path, no folder between it
and the root holds a `.git` or a `HEAD`, and the root's `.git` exists.
When a check fails it asks git again at once, and it re-asks every 10
minutes regardless. An answer the disk can't confirm is never reused.
Concurrent resolves of one folder share one git run.

A sweep now makes 11 lookups on its first pass and none after.
@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 21, 2026 6:04am UTC

Request Review

@badcuban
badcuban added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 86442cb Nov 21, 2026
23 checks passed
@badcuban
badcuban deleted the perf/repository-identity-lookups branch November 21, 2026 06:52

This branch was previously deployed

1 inactive deployment
Preview — d9e80ce0 Deployed Nov 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant